#ifndef CPROPERTYITEM_H
#define CPROPERTYITEM_H

#include "CPropertyEditorItem.h"
#include <QStringList>
//#include <QObject>
//#include "CGroupItem.h"

class CGroupItem;

class CPropertyItem : public CPropertyEditorItem
{
    QString key;
    QString value;
    //bool readOnly;
    //QString displayName;
    //QStringList * stringList;
    //QStringList * GetStringList() { if( !stringList ) stringList = new QStringList; return stringList; }
    CGroupItem * group;
    friend class CGroupItem;
    void SetGroup( CGroupItem * g );
public:
    CPropertyItem( const QString & _key, const QString & _val ) :  key( _key ), value( _val ), group(0), ReadOnly( false ){}
    ~CPropertyItem() {}

    const QString & GetKey() const { return key; }
    virtual QString GetValue() const { return value; }
    virtual void SetValue( const QString & str );

    virtual void Map( std::vector< CPropertyEditorItem* > & v ) { v.push_back( this ); }
    virtual CPropertyEditor * Editor();

    virtual void UpdateValue( const QString & str );

    /*Q_PROPERTY(*/ QString DispalyName;/* READ displayName WRITE displayName )*/
    /*Q_PROPERTY(*/ QStringList * StringList;/* READ GetStringList )*/
    //*Q_PROPERTY(*/ int EditLen;
    /*Q_PROPERTY(*/ bool Modified;
    /*Q_PROPERTY(*/ bool ReadOnly;
};

//-------------------------------------

class CBoolPropertyItem : public CPropertyItem
{
    QString trueStr;
    QString falseStr;
    QString BoolToStr( bool v ) const { return v ? trueStr : falseStr; }
    bool StrToBool( const QString & str ) const;
    void SetStringList();

public:
    //explicit CBoolPropertyItem( const QString & _key, const char * _val );
    //explicit CBoolPropertyItem( const QString & _key, bool val );
    explicit CBoolPropertyItem( const QString & _key, const QString & _val ) : CPropertyItem( _key, _val ), trueStr("true"), falseStr("false") { SetStringList(); }

    virtual void SetValue( const QString& str ) { CPropertyItem::SetValue( BoolToStr( StrToBool( str ) ) ); }
    //virtual void UpdateValue( const QString& str ) { CPropertyItem::UpdateValue( BoolToStr( str == "true" ) ); }
    virtual QString GetValue() const { return StrToBool( CPropertyItem::GetValue() ) ? "true" : "false"; }
    virtual QString DisplayValue() const { return CPropertyItem::GetValue(); }

    virtual void Map( std::vector< CPropertyEditorItem* > & v ) {}
    //virtual CPropertyEditor * Editor() {}

    bool Value() const { return StrToBool( GetValue() ); }
    void Value( bool v );
    void SetTrueStr( const QString str );
    void SetFalseStr( const QString str );
    void SetTrueFalseStr( const QString _trueStr, const QString _falseStr );

    virtual void UpdateValue( const QString& str );

    Q_PROPERTY( QString TrueCaption READ trueStr WRITE SetTrueStr )
    Q_PROPERTY( QString FalseCaption READ falseStr WRITE SetFalseStr )

};

#endif // CPROPERTYITEM_H
